//
//  FriendListVC.m
//  ChangChat
//
//  Created by Cocoa on 2019/8/20.
//  Copyright © 2019 yibai. All rights reserved.
//

#import "FriendCell.h"

@implementation FriendCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    self.iconImageView = UIImageView.new;
    self.nameLabel = [UILabel k_labelWithFontSize:15 textColor:UIColor.k_t2Color];
    self.nameLabel.highlightedTextColor = UIColor.k_t1Color;
    
    [self.pContentView addSubview:self.iconImageView];
    [self.pContentView addSubview:self.nameLabel];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.mas_offset(11);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.bottom.mas_offset(-11);
    }];
    self.iconImageView.layer.cornerRadius = 20;
    self.iconImageView.layer.masksToBounds = YES;
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView.mas_right).offset(5);
        make.centerY.equalTo(self.iconImageView);
        make.right.mas_offset(-25);
    }];
    
    self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.bounds];
    self.selectedBackgroundView.backgroundColor = UIColor.whiteColor;
    self.backgroundColor =
    self.contentView.backgroundColor = global_viewBackgroundColor;
    
    self.iconImageView.image = UIImage.k_imgName(@"placeholder_user");
    self.nameLabel.text = @"李四";
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}


- (void)setFriendItem:(FriendItem *)friendItem {
    _friendItem = friendItem;
    
    [self.iconImageView sd_setImageWithURL:friendItem.avatar.toURL placeholderImage:UIImage.k_imgName(@"placeholder_user")];
    self.nameLabel.text = friendItem.displayName;
}


- (UIButton *)agreeBtn {
    if (_agreeBtn == nil) {
        _agreeBtn = UIButton.k_initType(UIButtonTypeCustom).k_title(@"同意").k_titleColor(UIColor.whiteColor).k_bgImgColor(UIColor.k_t1Color).k_cornerRadius(5.0f).k_font([UIFont systemFontOfSize:14]);
        [self.pContentView addSubview:_agreeBtn];
        [_agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_offset(-20);
            make.centerY.mas_offset(0);
            make.size.mas_equalTo(CGSizeMake(40, 26));
        }];
    }
    return _agreeBtn;
}
- (UIButton *)selectBtn {
    if (_selectBtn == nil) {
        _selectBtn = UIButton.k_initType(UIButtonTypeCustom);
        _selectBtn.k_img(UIImage.k_imgName(@"chat_select_normal"));
        _selectBtn.k_img_state(UIImage.k_imgName(@"chat_select_selected"), UIControlStateSelected);
        [self.pContentView addSubview:_selectBtn];
        [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_offset(-20);
            make.centerY.mas_offset(0);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
    }
    return _selectBtn;
}

@end
